<template>

	<view class="goods-item">
		<!-- 左侧图片区 -->
		<view class="goods-item-left">

			<radio v-if="showRadio" :checked="item.goods_state" color="#c00000" @click="radioClick"></radio>

			<image :src="item.goods_big_logo || item.goods_small_logo || defaultPic" class="goods-pic"></image>
		</view>
		<!-- 右侧详情区 -->
		<view class="goods-item-right">
			<view class="goods-name">{{item.goods_name}}</view>
			<view class="goods-info-box">
				<view class="goods-price">￥{{item.goods_price| tofixed}}</view>
				<uni-number-box v-if="showNum" :value="item.goods_count" :min="1" @change="numberChange"></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			item: {
				type: Object,
				default: {}
			},
			//获取控制勾选按钮是否出现的值
			showRadio:{
				type:Boolean,
				default:false
			},
			//获取数量按钮是否出现的值
			showNum:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				//设置一个默认的图片的地址
				defaultPic: '../../static/c3.png'
			};
		},
		methods:{
			//这是radio的点击事件处理函数
			radioClick(){
				//通过this.$emit触发外界的自定义函数
				this.$emit('radio-change',{
					goods_id:this.item.goods_id,
					goods_state:!this.item.goods_state
				})
			},
			//这是number-box的数据改变事件
			numberChange(val){
				this.$emit('num-change',{
					goods_id:this.item.goods_id,
					//这里的+是为了让val为数字类型
					goods_count: +val
				})
			}
		},
		//过滤器节点
		filters: {
			tofixed(num) {
				//保留两位小数,显示 .00
				return Number(num).toFixed(2)
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		width: 750rpx;
		//怪异盒子模型
		box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;

		.goods-item-left {
			display: flex;
			justify-content: space-between;
			align-items: center;
			.goods-pic {
				width: 100px;
				height: 100px;
				display: block;
				margin-right: 10px;
			}
		}

		.goods-item-right {
			display: flex;
			//沾满整个盒子
			flex:1;
			flex-direction: column;
			justify-content: space-between;

			.goods-name {
				font-size: 14px;
			}

			.goods-info-box {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.goods-price {
					color: #c00000;
					font-size: 18px;
				}
			}
		}
	}
</style>
